package com.xintonghua.bussiness.ui.user;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;

import com.alibaba.fastjson.JSONObject;
import com.xintonghua.base.widget.ShowAllListView;
import com.xintonghua.bussiness.R;
import com.xintonghua.bussiness.adapter.TaskManageAdapter;
import com.xintonghua.bussiness.base.BaseActivity;
import com.xintonghua.bussiness.bean.TaskBean;
import com.xintonghua.bussiness.bean.TaskManageResponse;
import com.xintonghua.bussiness.ui.home.TaskActivity;
import com.xintonghua.bussiness.ui.user.manage.SelectEmployeeActivity;
import com.xintonghua.bussiness.util.JumpUtils;
import com.xintonghua.bussiness.util.MyState;

import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 作者：wanxianyi
 * 时间：2018/2/28.
 * 包名：com.xintonghua.bussiness.ui.user
 * 任务管理
 */

public class TaskManageActivity extends BaseActivity {
    @BindView(R.id.tv_all_task)
    TextView tvAllTask;
    @BindView(R.id.tv_now_task)
    TextView tvNowTask;
    @BindView(R.id.tv_complete)
    CheckBox tvComplete;
    @BindView(R.id.lv_complete)
    ShowAllListView lvComplete;
    @BindView(R.id.tv_uncomplete)
    CheckBox tvUncomplete;
    @BindView(R.id.lv_uncomplete)
    ShowAllListView lvUncomplete;
    @BindView(R.id.tv_time_saix)
    TextView tv_time_saix;

    //要查看的那个人的id
    String id;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_manage_task);
        ButterKnife.bind(this);
        id = JumpUtils.getString(this, "id");
        Log.i("aaa", "id=o===>" + id);
        initUI();
        tv_time_saix.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                HashMap<String, String> map = new HashMap<>();
                map.put("taskType", "4");
                map.put("taskName", "时间筛选");
                map.put("shopUserId", "" + id);
                JumpUtils.jumpto(TaskManageActivity.this, TaskActivity.class, map);
            }
        });
    }

    @Override
    public void initUI() {
        super.initUI();
        onSimpleActionBar();
        setSimpleActionBar("目标完成情况", "查看详情", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bun = new Bundle();
                bun.putString("shopUserId", "" + id);
                bun.putString("taskType", "0");
                bun.putString("taskName", "今日目标");

                JumpUtils.jumptoB(TaskManageActivity.this, TaskActivity.class, bun);

//                openActivity(TaskActivity.class);
            }
        });
        httpCent.getTaskRecord(id, this, MyState.requestOne);
        httpCent.getTaskPerMonthList(id, this, MyState.requestTwo);
        tvComplete.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                lvComplete.setVisibility(isChecked ? View.VISIBLE : View.GONE);
            }
        });
        tvUncomplete.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                lvUncomplete.setVisibility(isChecked ? View.VISIBLE : View.GONE);
            }
        });

    }

    @Override
    public void dataBack(Object data, int order) {
        super.dataBack(data, order);
        switch (order) {
            case MyState.requestOne:
                TaskBean taskBean = JSONObject.parseObject((String) data, TaskBean.class);
                tvAllTask.setText(taskBean.getTotal() + "");
                tvNowTask.setText("当前完成  " + taskBean.getTotal());
                break;
            case MyState.requestTwo:
                TaskManageResponse response = JSONObject.parseObject((String) data, TaskManageResponse.class);
                TaskManageAdapter adapter = new TaskManageAdapter(response.getOkList(), this);
                lvComplete.setAdapter(adapter);
                TaskManageAdapter adapter1 = new TaskManageAdapter(response.getNoList(), this);
                lvUncomplete.setAdapter(adapter1);
                break;
        }
    }


}
